<?php session_start(); include_once('../functions.php');
if ($_SESSION["pass"] != check($_SESSION["user"])) { secure(); exit; } 
elseif(!isset($_SESSION["pass"])) { secure(); exit; }
header('Content-type: text/javascript'); ?>

var xmlHttp

function ChangePass() {
 var Newpass = prompt( "Please Enter a new password" , "");
         if (Newpass == null) {
         var comfirm = confirm("Are you sure you want to cancel changing your password?");
		 	if (comfirm == false) { ChangePass(); }
         } else if(Newpass == '') {
         var comfirm = confirm("Are you sure you want to cancel changing your password?");
		 	if (comfirm == false) { ChangePass(); }
         } else {
		NewPass(Newpass);
         }
}

function NewPass(Newpass)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="dirstuff.php";
url=url+"?newPassword="+Newpass;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
if(xmlHttp.responseText =='changed') { alert("Your password has been changed successfully."); } else { alert('oPanel failed to change your password.'); }
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}